package com.hua.common.commontools;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;


/**
 * Created by hxl on 2016/4/11.
 */
public class ContactsUtil {

    /**
     * 通过手机号码获取联系人姓名
     */
    private String getContactNameByNumber(Context context,String phoneNum) {
        String contactName = null;
        try {
            ContentResolver cr = context.getContentResolver();
            Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?",
                    new String[]{phoneNum}, null);
            if (pCur.getCount() > 0) {
                if (pCur.moveToFirst()) {
                    contactName = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    pCur.close();
                }
            }
        } catch (Exception e) {
            return contactName;
        }
        return contactName;
    }
}
